// Bubble sort 2D array

	#include<stdio.h>
	#include<conio.h>

	void main()
	{

	  int unsort[50][50], sort[100];
	  int i = 0, j = 0, temp, rows, cols;

	  clrscr();

	  printf("\n Enter the no of rows : ");
	  scanf("%1d",&rows);
	  printf("\n Enter the no of cols : ");
	  scanf("%1d",&cols);

	  clrscr();
	  for(i = 0;i < rows;i ++)
	   for(j = 0;j < cols; j ++)
	   {

	     gotoxy(10, 1);
	     printf("Enter the element [%d][%d] : ", i, j);
	     scanf("%d",&unsort[i][j]);
	     gotoxy(38, 1);
	     textbackground(BLACK);
	     cprintf("\b        ");

	   }

	  clrscr();
	  gotoxy(3, 3);
	  for(i = 0;i < rows;i ++)
	  {
	   for(j = 0;j < cols;j ++)
	    {

	      printf("%d\t", unsort[i][j]);
	    }

	   gotoxy(3, (3+i+1));
	  }

	  int elements = rows * cols;

	  gotoxy(10,10);
	  printf("The No of elements are : %d ", elements);

	  int put=0;

	  for(i = 0;i < rows;i ++)
	  {
	   for(j = 0;j < cols;j ++)
	   {
	     sort[put] = unsort[i][j];
	     put++;
	   }
	  }

	  for(i = 0;i < elements;i ++)
	   printf("\nThe element in sort is : %d    " , sort[i]);

	 //Now Sort Starts

	  for(i = 0;i < (elements + 1);i ++)
	   for(j = 0;j < (elements - i);j ++)
	    {
	      if(sort[j] > sort[j+1])
	      {

		temp = sort[j];
		sort[j] = sort[j+1];
		sort[j+1] = temp;

	      }
	    }

	  printf("\n");
	  for(i = 0;i < elements; i++)
	   printf("%d, ", sort[i]);

	  //Sort closed and also printed sorted array

	  getch();
	  clrscr();

	  // Now rep sorted array in 2D form

	  printf("Sorted 2D array is  : ");

	  put = 0;
	  gotoxy(10, 6);
	  for(i = 0;i < rows;i ++)
	  {
	   for(j = 0;j < cols;j ++)
	    {
	      printf("%d\t", sort[put]);
	      put ++;
	    }

	    gotoxy(10, (6+i+1));

	  }



	 getch();

	}

